package b2.widget.fort
{
	import b2.config.*;
	import b2.net.*;
	import b2.scene.*;
	import b2.util.*;
	import b2.widget.*;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filters.*;
	import flash.geom.Point;
	import flash.text.*;
	import flash.ui.Mouse;

	public class EnemyTankItem extends Sprite
	{
		//敌军索引
		private var enemyIndex:int;
		//鼠标悬浮信息
		private var itemTip:BasicMessage;
		
		public function EnemyTankItem(enemyIndex:int, enemyLevel:int, bossLevel:int)
		{
			super();
			this.enemyIndex = enemyIndex;
			var enemyConfig:EnemyConfig = Config.enemyConfigs[enemyIndex];
			var tankConfig:TankConfig = Config.objectConfigs[enemyConfig.tankIndex];
			//加载空槽位
			var rrect:Sprite = new Sprite();
			rrect.graphics.lineStyle(2.5, 0x27AAE1);
			rrect.graphics.drawRoundRect(0, 0, 68, 68, 25, 25);
			rrect.filters = [new DropShadowFilter(2, 45, 0x000000, 1, 2, 2, 1, 1, false)];
			addChild(rrect);
			//图标
			var TankIcon:Class = ResourceHelper.getInstance().getClassByName(tankConfig.iconImage);
			var tankIcon:Sprite = new TankIcon();
			tankIcon.x = 7.5;
			tankIcon.y = 7.5;
			//齐天大圣
			if (enemyConfig.tankIndex == 10015)
			{
				tankIcon.width = 76;
				tankIcon.height = 85;
			}
			//死亡骑士
			else if (enemyConfig.tankIndex == 10020)
			{
				tankIcon.width = 66;
				tankIcon.height = 66;
			}
			else
			{
				tankIcon.width = 55;
				tankIcon.height = 55;
			}
			tankIcon.filters = [new ColorMatrixFilter(enemyConfig.filter)];
			addChild(tankIcon);
			//BOSS
			if (bossLevel > 0)
			{
				var bossLevelText:TextField = new TextField();
				bossLevelText.selectable = false;
				bossLevelText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0xFF0000, true, true);
				bossLevelText.autoSize = TextFieldAutoSize.LEFT;
				bossLevelText.text = "B" + bossLevel + " ";
				bossLevelText.x = 2;
				bossLevelText.y = 2;
				addChild(bossLevelText);
			}
			//敌人等级
			var levelText:TextField = new TextField();
			levelText.selectable = false;
			levelText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0xFFFF00, true);
			levelText.autoSize = TextFieldAutoSize.LEFT;
			levelText.text = "Lv." + enemyLevel;
			levelText.x = 65 - levelText.width;
			levelText.y = 2;
			addChild(levelText);
			//敌人名字
			var tankTitle:TextField = new TextField();
			tankTitle.selectable = false;
			tankTitle.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000);
			tankTitle.autoSize = TextFieldAutoSize.LEFT;
			tankTitle.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			tankTitle.text = enemyConfig.name;
			tankTitle.x = 35 - tankTitle.width / 2;
			tankTitle.y = 47;
			addChild(tankTitle);
			
			addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			Mouse.cursor = "button";
			this.filters = [new ColorMatrixFilter(BFont.brightFilter)];
			if (itemTip == null)
			{
				var enemyConfig:EnemyConfig = Config.enemyConfigs[enemyIndex];
				var globalPoint:Point = this.parent.localToGlobal(new Point(this.x, this.y));
				itemTip = new BasicMessage(enemyConfig.description, BFont.roundRecColor, 0x000000, 200); 
				itemTip.x = globalPoint.x + this.width;
				itemTip.y = globalPoint.y;
				if (itemTip.x + itemTip.width > BFont.stageWidth)
					itemTip.x = globalPoint.x - itemTip.width;
				SceneManager.getInstance().currentScene.addChild(itemTip);
			}
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			Mouse.cursor = "auto";
			this.filters = null;
			if (itemTip != null && itemTip.parent != null)
			{
				itemTip.parent.removeChild(itemTip);
				itemTip = null;
			}
		}
		
	}
}